使用numpy pandas 读取csv文件及遍历 && 二者处理数据时间对比 | 您所在的位置:网站首页 › pandas 处理 csv 文件 › 使用numpy pandas 读取csv文件及遍历 && 二者处理数据时间对比 |
1 使用numpy 及 pandas 读取csv文件及遍历 1.1 numpy fin = np.loadtxt(self.path,dtype=np.str,delimiter=',') test_dict = {} data = fin[1:].tolist() for list1 in data: name,cid = list1 test_dict[cid] = name print(json.dumps(test_dict,ensure_ascii=False,indent=4))1.2 pandas data = pd.read_csv(self.path) print(data) print(data.describe()) print(data.head(5)) #前5行 print(data.iloc[0,:]) #第一行所有数据 print(data.iloc[[1,3,4],:]) #第2 4 6行 print(data.iloc[:,:]) #所有航所有列 print(data.loc[:,'cid']) for index,row in data.iterrows(): print(row['cid'],row['name'],type(row['cid']),type(row['name']))2 使用numpy pandas python原生方法 处理较大数据时的耗时对比 这部分先简单写下,后续补全。 制造一份5.5w条的假数据,统计部分列数值的 sum,mean numpy cost time: 2.8s pandas cost time: 10.2s python 原生方法 cost time: 37.6s 可见numpy 是最快的。
我也觉得numpy api用着更顺手,以后常用numpy 算了。。。 |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |